package com.psdi.element;

import com.psdi.manager.GameLoader;
import com.psdi.physics.Collider;
import com.psdi.window.GameJFrame;

import java.util.HashSet;
import java.util.Set;

public class KnifeAirflow extends ElementObject implements Collider {
    public Vector2D direction;
    public float atk = 20;
    public KnifeAirflow(){
        transform = new Transform();
        tag=Tag.FVX;
    }

    public ElementObject CreatKnifeAirflow(Position pos, Vector2D Direction) {
        this.transform = new Transform(pos,new Rotation(),new Size(90, 90));
        direction = Direction;
        transform.rotation.z = controldir();
        this.tag=Tag.FVX;
        setImage(GameLoader.iconMap2.get(tag.toString()).get(0));
        return this;
    }
    private int controldir(){
        if (direction.equals(Vector2D.DOWN)) {
            return 90;
        } else if (direction.equals(Vector2D.LEFT)) {
            return 180;
        } else if (direction.equals(Vector2D.UP)) {
            return 270;
        }
        else return 0;
    }
    @Override
    public void update() {
        setImage(GameLoader.iconMap2.get(tag.toString()).get(0));
        transform.position.add(direction.scalarMultiply(4f));
        if (transform.position.x<0 || transform.position.x > GameJFrame.GAME_WIDTH ||
                transform.position.y < 0 || transform.position.y > GameJFrame.GAME_HEIGHT) {
            setAlive(false); // 如果子弹超出边界，则标记为不存活
        }
    }

    @Override
    public Size colliderSize() {
        return transform.size;
    }

    @Override
    public Position colliderPosition() {
        return transform.position;
    }

    @Override
    public Tag colliderTag() {
        return this.tag;
    }

    @Override
    public Set<Tag> colliderFilterTag() {
        Set<Tag> set = new HashSet<>();
        set.add(Tag.BULLET);
        set.add(Tag.KNIFE);
        set.add(Tag.PLAYER);
        return set;
    }

    @Override
    public void onCollisionStay(ElementObject other) {
        if(other instanceof Enemy) {
            ((Enemy) other).setHp(((Enemy) other).getHp() - atk/5);
            other.transform.position.add(direction.scalarMultiply(10));
        }
        if(other instanceof Boss) {
            ((Boss) other).setHp(((Boss) other).getHp() - atk/5);
        }

    }
}
